/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       creature_icon_window.cpp

	$Header: /game/creature_icon_window.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "creature_icon_window.h"

#include "abstract_creature.h"
#include "bitmap_group.h"
#include "bitmap_group_cache.h"
#include "bitmap_layer_cache_window.h"

extern t_bitmap_group_cache const k_creature_select_bitmaps;

// ----------------------------------------------------------------
// display a creature / hero portrait in a ring, and include help text / right click
// ----------------------------------------------------------------
t_creature_icon_window::t_creature_icon_window( t_screen_rect const& rect, t_window* parent, 
		                                        t_abstract_creature const* stack, 
												bool force_awake_portrait )
					  : t_window( t_screen_rect(rect.left, rect.top, rect.left, rect.top),
					              k_completely_transparent, parent )
{
	t_bitmap_layer const* layer;
	t_screen_point        offset;
	t_window*             window;

	m_bitmaps = k_creature_select_bitmaps.get();
	m_size = rect.height();
	layer = m_bitmaps->find( "ring_released" );
	offset = m_bitmaps->find( "hero_icon" )->get_rect().top_left()
			 - layer->get_rect().top_left();
	m_icon = new t_bitmap_layer_cache_window( t_bitmap_layer_ptr(), offset, this, false );
	window = new t_bitmap_layer_window( layer, t_screen_point(0,0), this, false );

	set_size_from_children();
	if (stack != 0)
		set_creature( stack, force_awake_portrait );
}

void t_creature_icon_window::clear_creature()
{
	m_icon->set_help_balloon_text( "" );
	m_icon->set_bitmap( t_bitmap_layer_ptr() );
}

void t_creature_icon_window::set_creature( t_abstract_creature const* stack, bool force_awake_portrait )
{
	t_bitmap_layer_ptr icon;

	icon = stack->get_portrait( m_size, force_awake_portrait );
	m_icon->set_bitmap( icon );
	m_icon->set_help_balloon_text( stack->get_name() );
}
